home *** CD-ROM | disk | FTP | other *** search
/ Visual Basic Source Code / Visual Basic Source Code.iso / vbsource / clpsib / clipsib.frm (.txt) next >
Encoding:
Visual Basic Form  |  1995-05-08  |  29.8 KB  |  724 lines

  1. VERSION 2.00
  2. Begin Form Form1 
  3.    BackColor       =   &H00E0E0E0&
  4.    Caption         =   "Run This Program As An EXE File For Best Results"
  5.    ClientHeight    =   5460
  6.    ClientLeft      =   855
  7.    ClientTop       =   1500
  8.    ClientWidth     =   7845
  9.    Height          =   5865
  10.    Left            =   795
  11.    LinkMode        =   1  'Source
  12.    LinkTopic       =   "Form1"
  13.    ScaleHeight     =   364
  14.    ScaleMode       =   3  'Pixel
  15.    ScaleWidth      =   523
  16.    Top             =   1155
  17.    Width           =   7965
  18.    Begin ListBox ShoppingList 
  19.       BackColor       =   &H00FFFF00&
  20.       Height          =   1785
  21.       Left            =   360
  22.       TabIndex        =   8
  23.       Top             =   3240
  24.       Width           =   1455
  25.    End
  26.    Begin PictureBox FindPic 
  27.       BackColor       =   &H00C0C0C0&
  28.       Height          =   1695
  29.       Left            =   3720
  30.       ScaleHeight     =   111
  31.       ScaleMode       =   3  'Pixel
  32.       ScaleWidth      =   239
  33.       TabIndex        =   13
  34.       Top             =   3120
  35.       Visible         =   0   'False
  36.       Width           =   3615
  37.       Begin CommandButton Command2 
  38.          Caption         =   "Cancel"
  39.          Height          =   375
  40.          Left            =   2760
  41.          TabIndex        =   17
  42.          Top             =   1200
  43.          Width           =   735
  44.       End
  45.       Begin CommandButton Command1 
  46.          Caption         =   "OK"
  47.          Height          =   375
  48.          Left            =   1920
  49.          TabIndex        =   16
  50.          Top             =   1200
  51.          Width           =   735
  52.       End
  53.       Begin CheckBox Check2 
  54.          BackColor       =   &H00C0C0C0&
  55.          Caption         =   "Whole Word"
  56.          Height          =   375
  57.          Left            =   240
  58.          TabIndex        =   21
  59.          Top             =   1200
  60.          Width           =   1575
  61.       End
  62.       Begin CheckBox Check1 
  63.          BackColor       =   &H00C0C0C0&
  64.          Caption         =   "Case Sensitive"
  65.          Height          =   375
  66.          Left            =   240
  67.          TabIndex        =   19
  68.          Top             =   840
  69.          Width           =   1575
  70.       End
  71.       Begin TextBox FindTextBox 
  72.          Height          =   285
  73.          Left            =   1020
  74.          TabIndex        =   14
  75.          Top             =   345
  76.          Width           =   2385
  77.       End
  78.       Begin PictureBox FindTitle 
  79.          BackColor       =   &H009A6049&
  80.          Height          =   255
  81.          Left            =   -15
  82.          ScaleHeight     =   15
  83.          ScaleMode       =   3  'Pixel
  84.          ScaleWidth      =   239
  85.          TabIndex        =   15
  86.          Top             =   -15
  87.          Width           =   3615
  88.       End
  89.       Begin Label Label3 
  90.          Alignment       =   1  'Right Justify
  91.          BackColor       =   &H00C0C0C0&
  92.          Caption         =   "Find What:"
  93.          Height          =   255
  94.          Left            =   0
  95.          TabIndex        =   18
  96.          Top             =   390
  97.          Width           =   975
  98.       End
  99.    End
  100.    Begin PictureBox PyramidPic 
  101.       AutoSize        =   -1  'True
  102.       Height          =   495
  103.       Index           =   2
  104.       Left            =   4080
  105.       ScaleHeight     =   31
  106.       ScaleMode       =   3  'Pixel
  107.       ScaleWidth      =   39
  108.       TabIndex        =   12
  109.       Top             =   1680
  110.       Visible         =   0   'False
  111.       Width           =   615
  112.    End
  113.    Begin ListBox MeatList 
  114.       Height          =   1590
  115.       Left            =   360
  116.       Sorted          =   -1  'True
  117.       TabIndex        =   4
  118.       Top             =   1200
  119.       Visible         =   0   'False
  120.       Width           =   1455
  121.    End
  122.    Begin PictureBox PyramidPic 
  123.       AutoSize        =   -1  'True
  124.       Height          =   495
  125.       Index           =   1
  126.       Left            =   4080
  127.       ScaleHeight     =   31
  128.       ScaleMode       =   3  'Pixel
  129.       ScaleWidth      =   39
  130.       TabIndex        =   11
  131.       Top             =   960
  132.       Visible         =   0   'False
  133.       Width           =   615
  134.    End
  135.    Begin ListBox VegList 
  136.       Height          =   1590
  137.       Left            =   720
  138.       Sorted          =   -1  'True
  139.       TabIndex        =   5
  140.       Top             =   960
  141.       Visible         =   0   'False
  142.       Width           =   1455
  143.    End
  144.    Begin ListBox FruitList 
  145.       Height          =   1590
  146.       Left            =   1080
  147.       Sorted          =   -1  'True
  148.       TabIndex        =   6
  149.       Top             =   720
  150.       Visible         =   0   'False
  151.       Width           =   1455
  152.    End
  153.    Begin ListBox PastryList 
  154.       Height          =   1590
  155.       Left            =   1440
  156.       Sorted          =   -1  'True
  157.       TabIndex        =   7
  158.       Top             =   480
  159.       Visible         =   0   'False
  160.       Width           =   1455
  161.    End
  162.    Begin PictureBox WindowPic 
  163.       BackColor       =   &H00808080&
  164.       Height          =   2655
  165.       Left            =   4800
  166.       ScaleHeight     =   175
  167.       ScaleMode       =   3  'Pixel
  168.       ScaleWidth      =   167
  169.       TabIndex        =   0
  170.       Top             =   240
  171.       Width           =   2535
  172.       Begin CommandButton ChessHelpCmdBut 
  173.          Caption         =   "Help"
  174.          Height          =   375
  175.          Left            =   960
  176.          TabIndex        =   2
  177.          Top             =   2160
  178.          Visible         =   0   'False
  179.          Width           =   735
  180.       End
  181.       Begin PictureBox ChessPic 
  182.          AutoSize        =   -1  'True
  183.          Height          =   615
  184.          Left            =   0
  185.          ScaleHeight     =   39
  186.          ScaleMode       =   3  'Pixel
  187.          ScaleWidth      =   55
  188.          TabIndex        =   1
  189.          Top             =   0
  190.          Visible         =   0   'False
  191.          Width           =   855
  192.       End
  193.    End
  194.    Begin PictureBox PyramidPic 
  195.       AutoSize        =   -1  'True
  196.       Height          =   495
  197.       Index           =   0
  198.       Left            =   4080
  199.       ScaleHeight     =   31
  200.       ScaleMode       =   3  'Pixel
  201.       ScaleWidth      =   39
  202.       TabIndex        =   3
  203.       Top             =   240
  204.       Visible         =   0   'False
  205.       Width           =   615
  206.    End
  207.    Begin Label Label4 
  208.       Alignment       =   2  'Center
  209.       BackColor       =   &H000000FF&
  210.       BorderStyle     =   1  'Fixed Single
  211.       Caption         =   "Drag FIND Box Around By Its Title Bar"
  212.       Height          =   255
  213.       Left            =   3720
  214.       TabIndex        =   20
  215.       Top             =   4920
  216.       Width           =   3615
  217.    End
  218.    Begin Label Label1 
  219.       Alignment       =   2  'Center
  220.       BackColor       =   &H00C0C0C0&
  221.       BorderStyle     =   1  'Fixed Single
  222.       Caption         =   "Shopping List"
  223.       Height          =   255
  224.       Left            =   360
  225.       TabIndex        =   9
  226.       Top             =   3000
  227.       Width           =   1455
  228.    End
  229.    Begin Label Label2 
  230.       Alignment       =   2  'Center
  231.       BackColor       =   &H000000FF&
  232.       BorderStyle     =   1  'Fixed Single
  233.       Caption         =   "Use Lists To Build A Shopping List"
  234.       Height          =   255
  235.       Left            =   120
  236.       TabIndex        =   10
  237.       Top             =   120
  238.       Width           =   3375
  239.    End
  240. '=========================================================
  241. '                  CLPSIB.BAS Rev. 1.0
  242. '              Keith Funk (CIS 72240, 2020)
  243. '                     Nov. 3, 1991
  244. '   Many thanks to Daniel Appleman (Desaware) for explaining
  245. '   the Win3 WS_CLIPSIBLINGS style without which this program
  246. '   could not have been written. I'd also like to thank
  247. '   Ted Young and Jonathan Zuk for the help they have given
  248. '   me in learning the Win3 API.
  249. '   The purpose of the program is to demonstrate how to
  250. '   implement overlapping controls in a VB program.
  251. '   NOTE that the Form and all controls have their ScaleMode set
  252. '   to PIXELS. Also, AutoRedraw is False for all controls. The
  253. '   Picture Controls that contain the bitmaps PYRAMID.BMP
  254. '   and CHESS.BMP have AutoSize set to True. No other control
  255. '   properties have any particular relevance for this demo.
  256. '   The program is FREEWARE. Feel free to use any part of
  257. '   it in your own programs. Feedback and comments would
  258. '   be appreciated. Have fun.
  259. '=========================================================
  260. '-- Declarations for external functions.
  261. '   CTLHWND.DLL is a custom DLL written by Jonathan Zuk. It
  262. '   is included, with thanks to Jonathan, as part of CLPSIB.
  263. Declare Function ControlhWnd Lib "ctlhwnd.dll" (Ctl As Control) As Integer
  264. Declare Sub BringWindowToTop Lib "User" (ByVal hWnd As Integer)
  265. Declare Sub SetWindowPos Lib "User" (ByVal hWnd As Integer, ByVal hWndInsertAfter As Integer, ByVal X As Integer, ByVal Y As Integer, ByVal cx As Integer, ByVal cy As Integer, ByVal wFlags As Integer)
  266. Declare Function GetWindow Lib "User" (ByVal hWnd As Integer, ByVal wCmd As Integer) As Integer
  267. Declare Function GetNextWindow Lib "User" (ByVal hWnd As Integer, ByVal wFlag As Integer) As Integer
  268. Declare Function GetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer) As Long
  269. Declare Function SetWindowLong Lib "User" (ByVal hWnd As Integer, ByVal nIndex As Integer, ByVal dwNewLong As Long) As Long
  270. Declare Function GetWindowsDirectory Lib "Kernel" (ByVal lpBuffer As String, ByVal nSize As Integer) As Integer
  271. Declare Function OpenFile Lib "Kernel" (ByVal lpFileName As String, lpReOpenBuff As OFSTRUCT, ByVal wStyle As Integer) As Integer
  272. '-- Window style.
  273. Const WS_CLIPSIBLINGS = &H4000000   '-- THE SECRET TO SUCCESS<g>
  274. '-- SetWindowPos Flags
  275.  Const SWP_NOSIZE = &H1
  276.  Const SWP_NOMOVE = &H2
  277.  Const SWP_NOZORDER = &H4
  278.  Const SWP_NOREDRAW = &H8
  279.  Const SWP_NOACTIVATE = &H10
  280.  Const SWP_DRAWFRAME = &H20
  281.  Const SWP_SHOWWINDOW = &H40
  282.  Const SWP_HIDEWINDOW = &H80
  283.  Const SWP_NOCOPYBITS = &H100
  284.  Const SWP_NOREPOSITION = &H200
  285. '-- GetWindow() Constants
  286. Const GW_HWNDFIRST = 0
  287. Const GW_HWNDLAST = 1
  288. Const GW_HWNDNEXT = 2
  289. Const GW_HWNDPREV = 3
  290. Const GW_OWNER = 4
  291. Const GW_CHILD = 5
  292. '-- Window field offsets for GetWindowLong() and GetWindowWord()
  293. Const GWL_WNDPROC = (-4)
  294. Const GWW_HINSTANCE = (-6)
  295. Const GWW_HWNDPARENT = (-8)
  296. Const GWW_ID = (-12)
  297. Const GWL_STYLE = (-16)
  298. Const GWL_EXSTYLE = (-20)
  299. '-- OpenFile action.
  300. Const OF_EXIST = &H4000
  301. Const True = -1
  302. Const False = 0
  303. '-- The mouse location when the mouse button is initially pressed.
  304. Dim XStart As Single
  305. Dim YStart As Single
  306. '-- Flags to indicate when a picture can be moved. A move
  307. '   is not allowed while a DoEvents is in progress.
  308. Dim OkToMoveChessPic As Integer
  309. Dim OkToMovePyramidPic As Integer
  310. Dim OkToMoveFindPic As Integer
  311. '-- Keeps track of the location of the list boxes in the
  312. '   window stack.
  313. Dim TopListBox As Integer
  314. Dim PrecedingListBox As Integer
  315. '-- Flag to determine if user clicked a listbox to make
  316. '   a selection or just to bring it to the front.
  317. Dim ClickedToGetFocus As Integer
  318. '---------------------------------------------------------
  319. '   This routine brings ThisList to the top of the window
  320. '   stack so it appears on top of the other listboxes.
  321. '   It also sets some global variables that keep track of
  322. '   the current order of the window stack.
  323. '---------------------------------------------------------
  324. Sub BringToTop (ThisList As Control)
  325.     '-- If ThisList is already at the top then there's nothing to do.
  326.     If ControlhWnd(ThisList) = TopListBox Then Exit Sub
  327.     '-- Put the listbox that is currently on top back in its proper location.
  328.     '   Note that we don't need to specify x,y,cx and cy because the flags
  329.     '   SWP_NOMOVE and SWP_NOSIZE tell Win3 to ignore these values.
  330.     Call SetWindowPos(TopListBox, PrecedingListBox, 0, 0, 0, 0, (SWP_NOMOVE Or SWP_NOSIZE))
  331.     '-- Find out which window precedes ThisList in the window stack.
  332.     PrecedingListBox = GetNextWindow(ControlhWnd(ThisList), GW_HWNDPREV)
  333.     '-- Move this listbox to the front of the group of
  334.     '   listboxes *BUT* behind the FindPic control. We are
  335.     '   demonstrating how a control (FindPic) can *always*
  336.     '   remain in front of all other controls even when
  337.     '   these controls are being re-arranged.
  338.     TopListBox = ControlhWnd(ThisList)
  339.     Call SetWindowPos(TopListBox, ControlhWnd(FindPic), 0, 0, 0, 0, (SWP_NOSIZE Or SWP_NOMOVE))
  340.     '-- Tell Click Event to ignore this click because
  341.     '   user is just bringing the list to the front.
  342.     ClickedToGetFocus = True
  343. End Sub
  344. '---------------------------------------------------------
  345. '   The main purpose of this control is to demonstrate
  346. '   how setting the WS_CLIPSIBLINGS style bit allows you
  347. '   to slide a picture underneath another control. NOTE
  348. '   that this control has been placed on the WindowPic
  349. '   control. It is *not* on Form1.
  350. '---------------------------------------------------------
  351. Sub ChessHelpCmdBut_Click ()
  352.     MsgBox "Use the LEFT Mouse Button to drag the small pictures on top of CHESS.BMP and to scroll CHESS.BMP.", 64, "Chess Help"
  353. End Sub
  354. '---------------------------------------------------------
  355. '   This control is filled with the bitmap CHESS.BMP
  356. '   during the Form1_Load Event. Because its AutoSize
  357. '   Property is set to True, it becomes much larger than
  358. '   the WindowPic control on which it is placed, but you
  359. '   can only see the area of CHESS.BMP that is within
  360. '   the boundaries of WindowPic. However, you can use your
  361. '   mouse to -move- different parts of CHESS.BMP into the
  362. '   visible area. NOTE how the picture -slides under- the
  363. '   Help Command Button. Too neat.<g>
  364. '   This is where the moving of CHESS.BMP begins. It is
  365. '   continued in the MouseMove Event.
  366. '---------------------------------------------------------
  367. Sub ChessPic_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  368.     '-- Save mouse X/Y so MouseMove can determine how far
  369.     '   the mouse has moved.
  370.     XStart = X: YStart = Y
  371.     '-- Set flag for MouseMove.
  372.     OkToMoveChessPic = True
  373. End Sub
  374. '---------------------------------------------------------
  375. '   This is the routine that actually moves CHESS.BMP.
  376. '   Note that the flag OkToMoveChessPic and the DoEvents
  377. '   are *absolutely* essential to the correct operation
  378. '   of this routine.
  379. '---------------------------------------------------------
  380. Sub ChessPic_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  381.     '-- Only move the picture if left button is down.
  382.     If Button = 1 Then
  383.         '-- Only move the picture if no DoEvent is in progress.
  384.         If OkToMoveChessPic = True Then
  385.             OkToMoveChessPic = False
  386.             ChessPic.Move (ChessPic.Left + X - XStart), (ChessPic.Top + Y - YStart)
  387.             q% = DoEvents()
  388.             OkToMoveChessPic = True     '-- DoEvents has finished.
  389.         End If
  390.     End If
  391. End Sub
  392. '--------------------------------------------------------
  393. '   In a -real- program, this button would activate the
  394. '   code to find text.
  395. '--------------------------------------------------------
  396. Sub Command1_Click ()
  397.     MsgBox "You Actually Expected Something To Happen?<g>", 0, " "
  398. End Sub
  399. '---------------------------------------------------------------------------
  400. '   Fills the meat, vegetable, fruit and pastry lists with goodies.
  401. '---------------------------------------------------------------------------
  402. Sub FillLists ()
  403.     '-- Fill the Meat List.
  404.     MeatList.AddItem "Rib Roast"
  405.     MeatList.AddItem "Pork Chops"
  406.     MeatList.AddItem "Chicken"
  407.     MeatList.AddItem "Ground Beef"
  408.     MeatList.AddItem "Lamb Chops"
  409.     MeatList.AddItem "Spare Ribs"
  410.     MeatList.AddItem "Pigs Feet"
  411.     MeatList.AddItem "Sausage"
  412.     MeatList.AddItem "Hot Dogs"
  413.     '-- Fill the Vegetable List.
  414.     VegList.AddItem "Potatoes"
  415.     VegList.AddItem "Onions"
  416.     VegList.AddItem "Corn"
  417.     VegList.AddItem "Peas"
  418.     VegList.AddItem "Turnip"
  419.     VegList.AddItem "Carrots"
  420.     VegList.AddItem "Yams"
  421.     VegList.AddItem "Beans"
  422.     VegList.AddItem "Eggplant"
  423.     VegList.AddItem "Celery"
  424.     '-- Fill the Fruit List
  425.     FruitList.AddItem "Apples"
  426.     FruitList.AddItem "Oranges"
  427.     FruitList.AddItem "Pears"
  428.     FruitList.AddItem "Grapes"
  429.     FruitList.AddItem "Melons"
  430.     FruitList.AddItem "Lemons"
  431.     FruitList.AddItem "Limes"
  432.     FruitList.AddItem "Apricots"
  433.     FruitList.AddItem "Quinces"
  434.     FruitList.AddItem "Plums"
  435.     FruitList.AddItem "Peaches"
  436.     '-- Fill the Pastry List
  437.     PastryList.AddItem "Donuts"
  438.     PastryList.AddItem "Bread"
  439.     PastryList.AddItem "Buns"
  440.     PastryList.AddItem "Crullers"
  441.     PastryList.AddItem "Cherry Pie"
  442.     PastryList.AddItem "Lemon Cake"
  443.     PastryList.AddItem "Cookies"
  444.     PastryList.AddItem "Macaroons"
  445.     PastryList.AddItem "Muffins"
  446.     PastryList.AddItem "Brownies"
  447.     PastryList.AddItem "Date Squares"
  448.     PastryList.AddItem "Peach Pie"
  449. End Sub
  450. '---------------------------------------------------------------------------
  451. '   This Picture Control acts as a dark blue title bar for the FindPic
  452. '   Picture Control. Its purpose is to allow FindPic and all its child
  453. '   windows to be dragged around the Form.
  454. '   NOTE: That FindPic *always* appears on top of any other control.
  455. '   Very desireable for a Find Dialog Box.
  456. '---------------------------------------------------------------------------
  457. Sub FindTitle_MouseDown (Button As Integer, Shift As Integer, X As Single, Y As Single)
  458.     '-- Save mouse X/Y so MouseMove can determine how far
  459.     '   the mouse has moved.
  460.     XStart = X: YStart = Y
  461.     '-- Set flag for MouseMove.
  462.     OkToMoveFindPic = True
  463. End Sub
  464. '---------------------------------------------------------------------------
  465. '   This is the routine that actually drags FindPic around.
  466. '---------------------------------------------------------------------------
  467. Sub FindTitle_MouseMove (Button As Integer, Shift As Integer, X As Single, Y As Single)
  468.     '-- Only move the picture if left button is down.
  469.     If Button = 1 Then
  470.         '-- Only move the picture if no DoEvent is in progress.
  471.         If OkToMoveFindPic = True Then
  472.             OkToMoveFindPic = False
  473.             FindPic.Move (FindPic.Left + X - XStart), (FindPic.Top + Y - YStart)
  474.             q% = DoEvents()
  475.             OkToMoveFindPic = True     '-- DoEvents has finished.
  476.         End If
  477.     End If
  478. End Sub
  479. Sub Form_Load ()
  480.     Dim WinDir As String
  481.     Dim ChessBmp As String
  482.     Dim PyramidBmp As String
  483.     '-- Display hourglass mousepointer.
  484.     Screen.MousePointer = 11
  485.     '-- Show the window centered on the screen.
  486.     Form1.Left = (Screen.Width - Form1.Width) / 2
  487.     Form1.Top = (Screen.Height - Form1.Height) / 2
  488.     Form1.Show
  489.     '**********************************************************************
  490.     '*   THIS IS THE KEY TO THE ENTIRE DEMO. TRY COMMENTING OUT           *
  491.     '*   THE CALL TO SetClipSiblings AND WATCH THE PROGRAM FALL TO PIECES.*
  492.     '******************************************************************** *
  493.     '-- Set the CLIPSIBLING Style bit for all child windows.
  494.     Call SetClipSiblingBit(Form1.hWnd)
  495.     '----------------------------------------------------
  496.     ' SET UP THE CHESS.BMP CONTROLS.
  497.     '----------------------------------------------------
  498.     '-- Find the Win3 directory and append a backslash.
  499.     WinDir = Space$(144)
  500.     r% = GetWindowsDirectory(WinDir, 144)
  501.     If r% = 0 Then
  502.         MsgBox "Can't Find Window's Directory", 0, "Fatal Error"
  503.         End
  504.     Else
  505.         WinDir = Left$(WinDir, r%)  '-- Strip trailing \0.
  506.         If Right$(WinDir, 1) <> "\" Then
  507.             WinDir = WinDir + "\"
  508.         End If
  509.     End If
  510.     '-- If CHESS.BMP exists, load it into ChessPic.
  511.     ChessBmp = WinDir + "CHESS.BMP" + Chr$(0)
  512.     If OpenFile(ChessBmp, Buffer, OF_EXIST) = -1 Then
  513.         MsgBox "Sorry, This Program Requires The Win3 Bitmap CHESS.BMP.", 0, "FATAL ERROR"
  514.         End
  515.     Else
  516.         ChessPic.Picture = LoadPicture(ChessBmp)
  517.     End If
  518.     '-- Put the Command Button for CHESS.BMP on top of the
  519.     '   Chess Picture, so the picture can be scrolled
  520.     '   underneath it.
  521.     Call BringWindowToTop(ControlhWnd(ChessHelpCmdBut))
  522.     '-- If PYRAMID.BMP exists, load it into the three PyramidPic controls.
  523.     PyramidBmp = WinDir + "PYRAMID.BMP" + Chr$(0)
  524.     If OpenFile(PyramidBmp, Buffer, OF_EXIST) = -1 Then
  525.         MsgBox "Sorry, This Program Requires The Win3 Bitmap PYRAMID.BMP.", 0, "FATAL ERROR"
  526.         End
  527.     Else
  528.         For I% = 0 To 2
  529.             PyramidPic(I%).Picture = LoadPicture(PyramidBmp)
  530.         Next I%
  531.     End If
  532.     '-- Make sure the PyramidPics are higher in the window stack than
  533.     '   WindowPic so they will appear on top of CHESS.BMP.
  534.     Call SetWindowPos(ControlhWnd(WindowPic), ControlhWnd(PyramidPic(2)), 0, 0, 0, 0, (SWP_NOSIZE Or SWP_NOMOVE))
  535.     Call SetWindowPos(ControlhWnd(PyramidPic(2)), ControlhWnd(PyramidPic(1)), 0, 0, 0, 0, (SWP_NOSIZE Or SWP_NOMOVE))
  536.     Call SetWindowPos(ControlhWnd(PyramidPic(1)), ControlhWnd(PyramidPic(0)), 0, 0, 0, 0, (SWP_NOSIZE Or SWP_NOMOVE))
  537.     '-- Display the Chess demo controls.
  538.     ChessPic.Visible = True
  539.     ChessHelpCmdBut.Visible = True
  540.     For I% = 0 To 2
  541.         PyramidPic(I%).Visible = True
  542.     Next I%
  543.     '----------------------------------------------------
  544.     '   SET UP THE LIST BOX CONTROLS.
  545.     '----------------------------------------------------
  546.     '-- Add items to the lists.
  547.     Call FillLists
  548.     '-- Place the controls in their correct order.
  549.     '   Meat, Veg, Fruit then Pastry.
  550.     Call SetWindowPos(ControlhWnd(VegList), ControlhWnd(MeatList), 0, 0, 0, 0, (SWP_NOMOVE Or SWP_NOSIZE))
  551.     Call SetWindowPos(ControlhWnd(FruitList), ControlhWnd(VegList), 0, 0, 0, 0, (SWP_NOMOVE Or SWP_NOSIZE))
  552.     Call SetWindowPos(ControlhWnd(PastryList), ControlhWnd(FruitList), 0, 0, 0, 0, (SWP_NOMOVE Or SWP_NOSIZE))
  553.     '-- Display them.
  554.     q% = DoEvents()     '-- improves the way Win3 initially paints the display.
  555.     MeatList.Visible = True
  556.     VegList.Visible = True
  557.     FruitList.Visible = True
  558.     PastryList.Visible = True
  559.     '-- Set Global variables to keep track of which listbox
  560.     '   is on top and which list it normally comes after.
  561.     TopListBox = ControlhWnd(MeatList)
  562.     PrecedingListBox = GetNextWindow(TopListBox, GW_HWNDPREV)
  563.     '-----------------------------------------------------------------------
  564.     '   SET UP THE FIND CONTROLS.
  565.     '-----------------------------------------------------------------------
  566.     '-- Make the Find "dialog box" the top most child
  567.     '   window of the Form, so it is *always* displayed on top of
  568.     '   all other child windows. Then make it visible.
  569.     q% = DoEvents()     '-- improves the way Win3 initally paints the screen.
  570.     Call BringWindowToTop(ControlhWnd(FindPic))
  571.     FindPic.Visible = True
  572.     '-- Set standard mousepointer.
  573.     Screen.MousePointer = 0
  574.         
  575. End Sub
  576. '---------------------------------------------------------------------------
  577. '   Adds the item selected from FruitList to the ShoppingList.
  578. '---------------------------------------------------------------------------
  579. Sub FruitList_Click ()
  580.     '-- Don't do anything if user just clicked to bring
  581.     '   the list to the front.
  582.     If ClickedToGetFocus = True Then
  583.         ClickedToGetFocus = False
  584.         Exit Sub
  585.     End If
  586.     '-- Add selected item to our shopping list.
  587.     ShoppingList.AddItem FruitList.List(FruitList.ListIndex)
  588. End Sub
  589. '---------------------------------------------------------------------------
  590. '   Displays this list on top of the other list boxes.
  591. '---------------------------------------------------------------------------
  592. Sub FruitList_GotFocus ()
  593.     Call BringToTop(FruitList)
  594. End Sub
  595. '---------------------------------------------------------------------------
  596. '   Adds the item selected from MeatList to the ShoppingList.
  597. '---------------------------------------------------------------------------
  598. Sub MeatList_Click ()
  599.     '-- Don't do anything if user just clicked to bring
  600.     '   the list to the front.
  601.     If ClickedToGetFocus = True Then
  602.         ClickedToGetFocus = False
  603.         Exit Sub
  604.     End If
  605.     '-- Add selected item to our shopping list.
  606.     ShoppingList.AddItem MeatList.List(MeatList.ListIndex)
  607. End Sub
  608. '---------------------------------------------------------------------------
  609. '   Displays this list on top of the other list boxes.
  610. '---------------------------------------------------------------------------
  611. Sub MeatList_GotFocus ()
  612.     Call BringToTop(MeatList)
  613. End Sub
  614. '---------------------------------------------------------------------------
  615. '   Adds the item selected from PastryList to the ShoppingList.
  616. '---------------------------------------------------------------------------
  617. Sub PastryList_Click ()
  618.     '-- Don't do anything if user just clicked to bring
  619.     '   the list to the front.
  620.     If ClickedToGetFocus = True Then
  621.         ClickedToGetFocus = False
  622.         Exit Sub
  623.     End If
  624.     '-- Add selected item to our shopping list.
  625.     ShoppingList.AddItem PastryList.List(PastryList.ListIndex)
  626. End Sub
  627. '---------------------------------------------------------------------------
  628. '   Displays this list on top of the other list boxes.
  629. '---------------------------------------------------------------------------
  630. Sub PastryList_GotFocus ()
  631.     Call BringToTop(PastryList)
  632. End Sub
  633. '----------------------------------------------------------------------------
  634. '   This is where the start of moving the small picture controls containing
  635. '   PYRAMID.BMP begins.
  636. '----------------------------------------------------------------------------
  637. Sub PyramidPic_MouseDown (Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  638.     '-- Save mouse X/Y so MouseMove can determine how far
  639.     '   the mouse has moved.
  640.     XStart = X: YStart = Y
  641.     '-- Set flag for MouseMove.
  642.     OkToMovePyramidPic = True
  643. End Sub
  644. '----------------------------------------------------------------------------
  645. '   This is the routine that actually moves the picture controls that
  646. '   contain PYRAMID.BMP.
  647. '----------------------------------------------------------------------------
  648. Sub PyramidPic_MouseMove (Index As Integer, Button As Integer, Shift As Integer, X As Single, Y As Single)
  649.     '-- Only move the picture if the left mouse button is down.
  650.     If Button = 1 Then
  651.         '-- Only move the picture if no DoEvent is in progress.
  652.         If OkToMovePyramidPic = True Then
  653.             OkToMovePyramidPic = False
  654.             PyramidPic(Index).Move (PyramidPic(Index).Left + X - XStart), (PyramidPic(Index).Top + Y - YStart)
  655.             q% = DoEvents()
  656.             OkToMovePyramidPic = True     '-- DoEvents has finished.
  657.         End If
  658.     End If
  659. End Sub
  660. '---------------------------------------------------------
  661. '   This routine sets the WS_CLIPSIBLINGS style bit for
  662. '   all child windows of the Parent window *and* any
  663. '   child windows of the child windows. The routine is
  664. '   recursive.
  665. '   *** THIS IS THE KEY ROUTINE OF THE PROGRAM. ***
  666. '   Setting the WS_CLIPSIBLINGS style bit is all that is
  667. '   needed to make VB work properly with overlapping
  668. '   controls. Or at least, so it appears to me.
  669. '--------------------------------------------------------
  670. Sub SetClipSiblingBit (ByVal hWndParent As Integer)
  671.     Dim hWndChild As Integer
  672.     Dim Style As Long
  673.     '-- Get the first child window.
  674.     hWndChild = GetWindow(hWndParent, GW_CHILD)
  675.     '-- Set the CLIPSIBLING bit for each child window.
  676.     '   Loop terminates when GetWindowNext runs out of
  677.     '   child windows and returns NULL.
  678.     Do
  679.         Style = GetWindowLong(hWndChild, GWL_STYLE) '-- Get current style.
  680.         Style = Style Or WS_CLIPSIBLINGS            '-- Set the bit.
  681.         Style = SetWindowLong(hWndChild, GWL_STYLE, Style) '-- Set new style.
  682.         
  683.         '-- Process any child windows of this window.
  684.         If GetWindow(hWndChild, GW_CHILD) <> 0 Then
  685.             Call SetClipSiblingBit(hWndChild)       '-- recursive call.
  686.         End If
  687.         
  688.         '-- Get the next top level child window.
  689.         hWndChild = GetNextWindow(hWndChild, GW_HWNDNEXT)
  690.     Loop Until hWndChild = 0
  691.         
  692. End Sub
  693. '---------------------------------------------------------------------------
  694. '   Adds the item selected from VegList to the ShoppingList.
  695. '---------------------------------------------------------------------------
  696. Sub VegList_Click ()
  697.     '-- Don't do anything if user just clicked to bring
  698.     '   the list to the front.
  699.     If ClickedToGetFocus = True Then
  700.         ClickedToGetFocus = False
  701.         Exit Sub
  702.     End If
  703.     '-- Add selected item to our shopping list.
  704.     ShoppingList.AddItem VegList.List(VegList.ListIndex)
  705. End Sub
  706. '---------------------------------------------------------------------------
  707. '   Displays this list on top of the other list boxes.
  708. '---------------------------------------------------------------------------
  709. Sub VegList_GotFocus ()
  710.     Call BringToTop(VegList)
  711. End Sub
  712. '---------------------------------------------------------
  713. '   This control is the Parent of the ChessPic control.
  714. '   That is, ChessPic has been placed *on* this control,
  715. '   *not* on Form1. It serves as a clipping window which
  716. '   restricts the amount of ChessPic which is visible.
  717. '   NOTE that ChessPic has its AutoSize Property set to
  718. '   True, so when CHESS.BMP is loaded into its Picture
  719. '   Property, ChessPic becomes *much* larger than this
  720. '   picture control.
  721. '---------------------------------------------------------
  722. Sub WindowPic_Click ()
  723. End Sub
  724.